/***************
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>
***************/
#ifndef HEADSETFINDER_H
#define HEADSETFINDER_H

#include <QObject>
#include <QTimerEvent>
#include "CortexClient.h"
#include "Headset.h"

/*
 * Find all headsets connected to this device.
 *
 * It looks for connected headsets every second, until it finds one.
 *
 */
class HeadsetFinder : public QObject
{
    Q_OBJECT

public:
    explicit HeadsetFinder(QObject *parent = nullptr);

    void findHeadsets(CortexClient* client);

    // break all connections between this object and the Cortex client
    void clear();

    void printHeadsets(const QList<Headset> &headsets);

signals:
    void headsetFound(const Headset &headset);

protected:
    void timerEvent(QTimerEvent *event);

private slots:
    void onQueryHeadsetsOk(const QList<Headset> &headsets);
    
public slots:
    void refreshList(CortexClient *client);

private:
    CortexClient* client;
    int timerId;
    bool _allowRefreshList = true;
};

#endif // HEADSETFINDER_H
